import { AuthError, authenticateRequest } from "@/lib/auth/server"; import { deleteConversation } from "@/lib/db/conversations"; import { getPool } from "@/lib/db/pool"; const noStoreHeaders = { "Cache-Control": "no-store" }; export async function DELETE( request: Request, { params }: { params: Promise<{ id: string }> }, ): Promise { try { const user = await authenticateRequest(request); const { id } = await params; const deleted = await deleteConversation(getPool(), user.id, id); if (!deleted) { return Response.json({ error: "Чат не найден" }, { status: 404, headers: noStoreHeaders }); } return new Response(null, { status: 204, headers: noStoreHeaders }); } catch (error) { const status = error instanceof AuthError ? 401 : 503; return Response.json( { error: status === 401 ? "Unauthorized" : "Хранилище чатов временно недоступно" }, { status, headers: noStoreHeaders }, ); } }